<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ include file="/WEB-INF/views/shared/taglib.jsp"%>
<%
	request.setAttribute("modelConfigPath", "studentManager");
%>
<%@ include file="/WEB-INF/views/shared/master/contentHeader.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/index.jsp"%>
<style type="text/css">
.panel-body{
	padding-top: 5px;
}
.custom-panel{
	margin-bottom: 0px;
	padding-top: 5px;
}
#weekLogSimpleAdd .form-group{
	margin-bottom: 3px !important;
	padding-bottom: 3px !important;
}
.custom-panel .panel-body{
	padding-bottom: 0px;
}
.table-weekLog .btn-custom.btn-icon {
	padding: 0px 3px !important;
}
#weekLogSimpleAdd{
	margin-top: 10px;
}
.searchPanel{
	border-radius:0px; 
}
.table-responsive{
	margin-top: 0px !important;
}

</style>
<div class="hide">
	<input type="hide" id="loginId" value="${sessionScope.session_account_info.loginId}" />
</div>
<c:import url="seniorSearch.jsp" />
<c:import url="weekLogInput.jsp" />
<t:form commandName="weekLogSearch" id="weekLogIndex"  action="/admin/studentManager/weekLog/index" ajaxPost="true" onSuccess="onSuccess">
	<t:panel cssClass="panel-flat border-top-xmd border-top-primary-300" customBody="true" customHead="true">
		<t:panelHead title='任务列表'></t:panelHead>
		<div class="panel-body">
			<div id="tableContent" class="row">
				<c:import url="output.jsp" />
			</div>
		</div>
	</t:panel>
</t:form>

<script type="text/javascript">
	$(function(){
		bindTrDblclick();		
	});

	function onSuccess(res){
		$("#tableContent").html(res);
		
		redrawTable();
		
		bindTrDblclick();
		
		loadTEditor();
	}
	function searchCallback(){
		formSubmit();
	}
	function pagerChangeCallback(){
		formSubmit();
	}
	function sortingCallback(){
		formSubmit();
	}
	function formSubmit(){
		$("#weekLogSearch:first").submit();	
	}
	
	function bindTrDblclick(){
		$(".table-weekLog").on("dblclick",function(){
			editData();
		});
	}
	
	function editData(){
		var id=getKeyId();
		if(isEditor(id)){
			top.openModal("/admin/studentManager/weekLog/weekLogDetailed?key="+id,"weekLog_form","任务详情-修改",800,445);
		}
	}
	
	function addData(){
		top.openModal("/admin/studentManager/weekLog/weekLogDetailed","weekLog_form","任务详情-新增",800,445);
	}
	
	function onFinish(taskId){
		var url=$.getVirtualPath()+"/admin/studentManager/weekLog/doFinish?taskId="+taskId;
		var result=$.getJsonPost(url);
		if(result.resultType=="success"){
			formSubmit();
		}else{
			$.topNotify(result.message,result.resultType);	
		}
	}
</script>
<style type="text/css">
.t-editor{
	/* color:#2196f3; */
	border-bottom:1px dotted #2196f3;
	cursor: pointer;
}
.t-editor-popover .popover-title{
	padding:5px 10px !important;
}
.t-editor-popover .popover-content{
	padding: 5px 5px 0px;
}
.t-editor-popover .popover-content textarea{
	border:1px solid #ddd;
}
</style>
<script type="text/javascript">
	$(function(){
		loadTEditor();
	});
	
	function loadTEditor(){
		$(".t-editor").each(function(){
			var $editor=$(this);
			var title=$editor.attr("data-title");
			var type=$editor.attr("data-type");
			var propertyName=$editor.attr("data-property");
			var key=$editor.attr("data-key");
			
			
			var options={};
			options.title=title;
			options.type=type;
			options.key=key;
			options.propertyName=propertyName;
			options.ajaxUrl=$.getVirtualPath()+"/admin/studentManager/weekLog/updateProperty";
			options.ajaxCallback=function(result){
				if(result.resultType=="success"){
					formSubmit();
				}else{
					$.topNotify(result.message,result.resultType);	
				}
			}
			$editor.tEditor(options);
		});	
	}
	
	
	$(function(){
		$("body").on("click",function(e){
			if(!$(e.target).hasClass("t-editor")&&$(e.target).parents(".t-editor-popover").length<=0){
				$(".t-editor").popover('hide');
			}
		});
	});
	;(function($){
		$.fn.tEditor=function(options){
			var $editor=$(this);
			var popoverId=$.random(100000000,999999999);
			$editor.attr("data-id","popover-"+popoverId);
			
			var settings={
				title:"请输入",
				type:'text',
				placement: 'top',
				trigger:'manual',
				container:'body',
				html:true,
				propertyName:'',
				key:'',
				ajaxUrl:'',
				ajaxCallback:null,
				okCallback:null
			}
			settings=$.extend(settings, options);
			
			var content='';
			if(settings.type=="text"){
				content='<textarea style="width:200px;" rows=3"">'+$.trim($editor.text())+'</textarea>';
			}else if(settings.type=="date"){
				content='<input id="popover-date" name="popover-date" class="form-control custom-input custom-pickadate picker__input picker__input--active" data-min="[]" data-control-type="input" data-selectmonths="true" data-selectyears="true" data-format="yyyy-mm-dd" type="text" value="'+$.trim($editor.text())+'" readonly="" aria-haspopup="true" aria-expanded="true" aria-readonly="false" aria-owns="forecastDate_root">';
			}
			var bottomBtn='<div class="btn-group" style="float:right;"><button class="btn btn-custom btn-default btn-icon btn-xs legitRipple on-success" type="button" value="button"><i class="icon-checkmark3 text-success"></i></button><button class="btn btn-custom btn-default btn-icon btn-xs legitRipple on-cancel" type="button" value="button"><i class="icon-cross2 text-danger"></i></button></div>';
			$editor.popover({
				title: settings.title,
				placement: settings.placement,
				trigger:settings.trigger,
				container:settings.container,
				html:settings.html,
				content: content,
				template: '<div data-type="'+settings.type+'" class="popover border-primary-400 t-editor-popover" data-popover-id="popover-'+popoverId+'"><div class="arrow"></div><h5 class="popover-title bg-primary-400"></h5><div class="popover-content"></div>'+bottomBtn+'</div>'
			}).on('show.bs.popover', function(e) {
				var $target=$(e.target);
				var dataId=$target.attr("data-id");	
				$(".t-editor:not([data-id='"+dataId+"'])").popover('hide');
				$(".t-editor-popover").on("click",function(){
					$(this).stopBubble("click");
				});
			});
			$editor.stopBubble("click");
			$editor.on("click",function(){
				$(this).popover("toggle");
				
				$(".t-editor-popover .btn-custom.on-success").on("click",function(){
					var type=$editor.attr("data-type");
					var resultValue="";
					if(type=="text"){
						resultValue=$(".t-editor-popover textarea").val();
					}else if(type=="date"){
						resultValue=$(".t-editor-popover #popover-date").val();
					}
					$editor.text(resultValue);
					$editor.popover("hide");
					var okResult=true;
					if(!$.isNull(settings.okCallback)){
						okResult=okCallback(resultValue);
					}
					if(okResult){
						if(!$.isNull(settings.propertyName)&&!$.isNull(settings.ajaxUrl)){
							var data="key="+settings.key+"&propertyName="+settings.propertyName+"&value="+resultValue;
							var result=$.getJsonPost(settings.ajaxUrl,data);
							if(!$.isNull(settings.ajaxCallback)){
								settings.ajaxCallback(result);
							}
						}
					}
				});
				$(".t-editor-popover .btn-custom.on-cancel").on("click",function(){
					$editor.popover("hide");
				});
				$(".t-editor-popover #popover-date").pickadateTrigger();
			});
		}
	})(jQuery);
</script>


<%@ include file="/WEB-INF/views/shared/master/cntable.jsp"%>

<%@ include file="/WEB-INF/views/shared/base/scripts/jqueryui.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formbuttons.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formstyling.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formselects.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formpickers.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/forminputs.jsp"%>

<%@ include file="/WEB-INF/views/shared//master/contentFooter.jsp"%>